<template>
  <div>
    <el-upload
      class="upload-demo"
      ref="upload"
      action=""
      :on-preview="handlePreview"
      :on-remove="handleRemove"
      :on-change="change"
      :file-list="fileList.File"
      list-type="picture"
      :auto-upload="false">
      <el-button slot="trigger" size="small" type="primary">选取文件</el-button>
      <el-button style="margin-left: 10px;" size="small" type="success" @click="submitUpload">上传文件</el-button>
      <div slot="tip" class="el-upload__tip">请上传身份证、营业执照附件</div>
    </el-upload>
    <!--<div v-for="file in fileArray" >-->
      <!--<img height="200px" width="200" style="text-align: center" :src="headerFile+file.attachmentAddr" alt="">-->
    <!--</div>-->
  </div>
</template>

<script>
  import {testService} from './testService'
  import {BusinessService} from '../businessRegistration/BusinessService'

    export default {
        name: "index",
      data() {
        return {
          fileList: [],
          imageUrl: '',
          file:'',
          headerFile: process.env.BASE_FILE_VIEW,
          formName: 'simple_business',
          formId: null,
          businessName: null
        };
      },
      props: [
        'files',
        'fileArray',
        'edit',
      ],
      methods: {
        handleRemove(file, fileList) {
          console.log(file, fileList);
        },
        handlePreview(file) {
          console.log(file);
        },
        submitUpload(file) {
          console.log("fileList",this.fileList)
          console.log("fromId",this.formId);
          testService.saveFile({name:'真是个笨比',associateFormId:this.formId,associateFormName:this.formName},this.fileList).then(res => {
            console.log("上传成功")
          })
            .catch((err) => {
              console.log("上传失败")
            })

          var router = this.$router;
          router.push({path: '/simple/businessRegistration/business'})
        },
        change(file) {
          console.log("file",file)
          this.fileList.push(file.raw);
        }
      },
      watch: {
        edit: {
          handler(newValue,oldValue){
            console.log("edit change",this.edit)
          }
        }
      },
      created() {
        this.businessName = this.$route.params.businessName;
        console.log("businessName",this.businessName)
        BusinessService.findBusinessWithName(this.businessName)
          .then((res) => {
            this.formId = res.data;
            console.log("读取成功")
          })
        .catch((err) => {
          console.log("读取失败")
        })
      }
    }
</script>

<style scoped lang="sass">

</style>
